package org.top10.parser;

import java.util.ArrayList;
import java.util.List;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

import org.top10.collector.Collector;
import org.top10.dealor.ConfReader;
import org.top10.entity.Blog;
import org.top10.entity.ConfBean;
import org.top10.entity.SinaBlogJsonData;
import org.top10.entity.SinaJsonData;
import org.top10.executor.ParseSource;
import org.top10.util.TOP10Global;
import org.w3c.dom.Node;


abstract class SinaBlogParser extends TOPParserImpl {

	public SinaBlogParser(String c, int t, String u) {
		super(c, t, u);
	}

	public abstract List parse(ParseSource doc) throws Exception;

	public abstract Blog build(Node node, int rank) throws Exception;

	// XUNlei所有解析器的公有方法放在这里..
	
	protected List<Blog> sinaBuild(ParseSource doc){
		//if(i>0){
			List<SinaBlogJsonData> SinaDatas=turnJson2List(doc.getTextSource().substring(17),SinaBlogJsonData.class);
			List<Blog> list = new ArrayList<Blog>();
			//int rank=1;
			for(SinaBlogJsonData d:SinaDatas){
				Blog blog = new Blog();
				blog.setName(d.getBlog_title());
				blog.setLinkUrl(d.getBlog_url());
				blog.setPoint(d.getBlog_hits());
				System.out.println(blog);
				list.add(blog);
			}
			return list;
	}
}

class SinaBlogDayTopParser extends SinaBlogParser{
	public SinaBlogDayTopParser(String c,  String u) {
		super(c,TOP10Global.TYPE_Blog, u);
	}
	public Blog build(Node node, int rank) throws Exception {
		return null;
	}
	public List parse(ParseSource doc) throws Exception {
		return sinaBuild(doc);
	}
}
